import ReactDom from "react-dom/client"
import Loading from "./loading";

import './loading.less';

let count = 0;

// 打开loading
export const showLoading = () => {
    if (count === 0) {
        const dom = document.createElement("div");
        dom.setAttribute("id", "loading");
        document.body.appendChild(dom);
        ReactDom.createRoot(dom).render(<Loading tip="正在加载中请稍等"></Loading>);
    }
    count++
}


// 关闭loading
export const hideLoading = () => {
    if (count < 0) return
    count--
    if (count === 0) {
        document.body.removeChild(document.getElementById("loading") as HTMLDivElement);
    }
}